<script type="text/javascript" charset="utf-8" src="lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="lib/ueditor/1.4.3/ueditor.all.js"> </script>
<script type="text/javascript" charset="utf-8" src="lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 网站管理 <span class="c-gray en">&gt;</span> 内容管理<span class="c-gray en">&gt;</span> 添加内容</nav>
	<div id="sectionContent" class="Hui-article">
		<article class="page-container">
			<div class="form form-horizontal" id="form-admin-add">
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>标题：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" class="input-text" id="title" name="title">
					</div>
				</div>
        <div class="row cl">
					<label class="form-label col-xs-4 col-sm-3">简介：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<textarea id="introduction" cols="" rows="" class="textarea" onKeyUp="textarealength(this,100)"></textarea>
						<p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
					</div>
				</div>
        <div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>关键字：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" class="input-text" id="keywords" name="keywords">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>标签：</label>
					<div class="formControls col-xs-8 col-sm-9">
							<span v-for="(row,index) in ltags">
									<label><input type="checkbox" name="ltag" value="{{(row,index).id}}"/>{{(row,index).ltName}}</label>
							</span>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>内容ICON：</label>
					<div class="formControls col-xs-8 col-sm-9">
            <input type="file" id="linkIconFile" class="input-text"  name="linkIcon" allowexts="gif,jpeg,jpg,png,bmp" accept="image/*">
						<input type="hidden" id="linkIcon">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>来源：</label>
					<div class="formControls col-xs-8 col-sm-9">
            <input type="text" class="input-text" id="sourceFrom" name="sourceFrom">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>来源Uri：</label>
					<div class="formControls col-xs-8 col-sm-9">
            <input type="text" class="input-text" id="sourceUri" name="sourceUri">
					</div>
				</div>
        <div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>作者：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" class="input-text" id="author" name="author">
					</div>
				</div>
        <div class="row cl">
					<label class="form-label col-xs-4 col-sm-3">内容：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<script id="editor" type="text/plain" style="height:350px;"></script>
					</div>
				</div>
				<div class="row cl">
					<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
						<input class="btn btn-primary" type="button" v-on:click="saveData()" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" style="margin-right:30px;">
						<input class="btn" type="button" onclick="javascript:history.go(-1)" value="&nbsp;&nbsp;取消&nbsp;&nbsp;">
					</div>
				</div>
			</div>
		</article>
	</div>
  <script type="text/javascript">
      var ue = UE.getEditor('editor');
			$(function(){
					$('#linkIconFile').bind('change',function(e){
							uplodFile();
					});
			});
			function uplodFile(){
					var formData = new FormData();
					var file = document.querySelector('[type=file]');
					formData.append('file', file.files[0]);
					$.ajax({
				          url: '/restful/cms/v1.0/common/ufile' ,
				          type: 'POST',
				          data: formData,
				          async: false,
				          cache: false,
				          contentType: false,
				          processData: false,
				          success: function (result) {
										 $('#linkIcon').val(result);
				          },
				          error: function (returndata) {
				              console.log(returndata);
				              alert('文件上传失败');
				          }
				     });
				}
  </script>
	<script>
    new Vue({
        el:'#sectionContent',
        http: authorization(),
				data:{
						ltags:[]
				},
				created:function(){
					this.$http.patch('/restful/cms/v1.0/ltag').then((response) => {
							this.ltags = responseObj(response).data;
					}).catch(function(response) {
							alert(errorMsg(response));
					});
				},
        methods:{
            backToList:function(){
                window.parent.location.href="#!view/cms/article/article-list.html?"+Math.random();
            },
            saveData:function(){
								var chk_value =[];
								$('input[name="ltag"]:checked').each(function(){
									chk_value.push($(this).val());
								});

                var formData = {
                    title:$('#title').val(),
                    introduction:$('#introduction').val(),
										keywords:$('#keywords').val(),
										linkIcon:$('#linkIcon').val(),
										sourceUri:$('#sourceUri').val(),
										sourceFrom:$('#sourceFrom').val(),
										labelTags:chk_value,
										classification:getQueryString('classification'),
										author:$('#author').val(),
										content:UE.getEditor('editor').getContent()
                };
                this.$http.post('/restful/cms/v1.0/article',formData).then((response) => {
                    this.backToList();
                }).catch(function(response) {
                    alert(errorMsg(response));
                });
            }
        }
    });
</script>
